package part12;

import part10.controller.BaseEvent;

/**
 * @author wcj
 * @Date 2021/5/21 15:15
 * @Version 1.0
 */
public class Part125 {

    public static void f() throws BaseException {
        System.out.println("parameter exception");
        throw new BaseException(1000, "未登录");
    }

    public static void main(String[] args) {
        try {
            f();
        } catch (BaseException e) {
            e.printStackTrace();
        }
    }
}

/**
 * 含有多个参数的自定义异常类，功能更加强大，Exception是异常的根类，因此catch捕获时最好放在最后
 */
class BaseException extends Exception {
    private Integer code;
    private String message;

    public BaseException() {
    }

    public BaseException(String msg) {
        super(msg);
    }

    public BaseException(Integer code, String msg) {
        this.code = code;
        this.message = msg;
    }

    @Override
    public String getMessage() {
        return "code:" + code + ",errMsg:" + message;
    }
}
